package com.chongchong.online.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chongchong.common.constant.ErrorCodeEnum;
import com.chongchong.online.entity.OnlineColumn;
import com.chongchong.online.entity.OnlineDatasourceRelation;
import com.chongchong.online.entity.constant.FieldFilterType;
import com.chongchong.online.entity.constant.FieldKind;
import com.chongchong.online.object.ColumnData;
import com.chongchong.online.service.IOnlineDatasourceRelationService;
import com.chongchong.online.service.IOnlineDatasourceService;
import com.chongchong.online.service.IOnlineOperationService;
import com.chongchong.online.service.IOnlineTableService;
import com.chongchong.core.tool.api.R;
import com.chongchong.online.dto.OnlineFilterDto;
import com.chongchong.online.entity.OnlineDatasource;
import com.chongchong.online.entity.OnlineTable;
import com.chongchong.user.entity.Attach;
import com.chongchong.user.feign.IAttachClient;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.task.Task;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 在线表单操作的通用帮助对象。
 *
 * @author Jerry
 * @date 2021-06-06
 */
@Slf4j
@Component
//@AllArgsConstructor
public class OnlineOperationHelper {
	@Autowired
    private IOnlineDatasourceService onlineDatasourceService;
	@Autowired
    private IOnlineDatasourceRelationService onlineDatasourceRelationService;
	@Autowired
    private IOnlineTableService onlineTableService;
	@Autowired
    private IOnlineOperationService onlineOperationService;
//	@Autowired(required = false)
//    private OnlineProperties onlineProperties;
//    private UpDownloaderFactory upDownloaderFactory;
	@Autowired
	private IAttachClient attachClient;

    /**
     * 验证并获取数据源数据。
     *
     * @param datasourceId 数据源Id。
     * @return 数据源详情数据。
     */
    public R<OnlineDatasource> verifyAndGetDatasource(Long datasourceId) {
        String errorMessage;
        OnlineDatasource datasource = onlineDatasourceService.getById(datasourceId);
        if (datasource == null) {
            return R.fail(ErrorCodeEnum.ARGUMENT_NULL_EXIST.getErrorMessage());
        }
        OnlineTable masterTable = onlineTableService.getOnlineTableFromCache(datasource.getMasterTableId());
        if (masterTable == null) {
            errorMessage = "数据验证失败，数据源主表Id不存在！";
            return R.fail(errorMessage);
        }
        datasource.setMasterTable(masterTable);
        return R.data(datasource);
    }

    /**
     * 验证并获取数据源的关联数据。
     *
     * @param datasourceId 数据源Id。
     * @param relationId   数据源关联Id。
     * @return 数据源的关联详情数据。
     */
    public R<OnlineDatasourceRelation> verifyAndGetRelation(Long datasourceId, Long relationId) {
        String errorMessage;
        OnlineDatasourceRelation relation = onlineDatasourceRelationService.getById(relationId);
        if (relation == null || !relation.getDatasourceId().equals(datasourceId)) {
            return R.fail(ErrorCodeEnum.DATA_NOT_EXIST.getErrorMessage());
        }
        OnlineTable slaveTable = onlineTableService.getOnlineTableFromCache(relation.getSlaveTableId());
        if (slaveTable == null) {
            errorMessage = "数据验证失败，数据源关联 [" + relation.getRelationName() + " ] 引用的从表不存在！";
            return R.fail(errorMessage);
        }
        relation.setSlaveTable(slaveTable);
        relation.setSlaveColumn(slaveTable.getColumnMap().get(relation.getSlaveColumnId()));
        return R.data(relation);
    }

    /**
     * 验证并获取数据源的一对多关联数据。
     *
     * @param datasourceId 数据源Id。
     * @param relationId   数据源一对多关联Id。
     * @return 数据源的一对多关联详情数据。
     */
    public R<OnlineDatasourceRelation> verifyAndGetOneToManyRelation(Long datasourceId, Long relationId) {
        String errorMessage;
        OnlineDatasourceRelation relation = onlineDatasourceRelationService.getById(relationId);
        if (relation == null || !relation.getDatasourceId().equals(datasourceId)) {
            return R.fail(ErrorCodeEnum.DATA_NOT_EXIST.getErrorMessage());
        }
       /* if (!relation.getRelationType().equals(RelationType.ONE_TO_MANY)) {
            errorMessage = "数据验证失败，数据源关联 [" + relation.getRelationName() + " ] 不是一对多关联，不能调用该接口！";
            return R.fail(errorMessage);
        }*/
        OnlineTable slaveTable = onlineTableService.getOnlineTableFromCache(relation.getSlaveTableId());
        if (slaveTable == null) {
            errorMessage = "数据验证失败，数据源关联 [" + relation.getRelationName() + " ] 引用的从表不存在！";
            return R.fail(errorMessage);
        }
        relation.setSlaveTable(slaveTable);
        relation.setSlaveColumn(slaveTable.getColumnMap().get(relation.getSlaveColumnId()));
        return R.data(relation);
    }

    /**
     * 验证并获取数据源的指定类型关联数据。
     *
     * @param datasourceId 数据源Id。
     * @param relationType 数据源关联类型。
     * @return 数据源指定关联类型的关联数据详情列表。
     */
    public R<List<OnlineDatasourceRelation>> verifyAndGetRelationList(
            Long datasourceId, Integer relationType) {
        String errorMessage;
        Set<Long> datasourceIdSet = CollUtil.newHashSet(datasourceId);
        List<OnlineDatasourceRelation> relationList = onlineDatasourceRelationService
                .getOnlineDatasourceRelationListByDatasourceIds(datasourceIdSet, relationType);
        for (OnlineDatasourceRelation relation : relationList) {
            OnlineTable slaveTable = onlineTableService.getOnlineTableFromCache(relation.getSlaveTableId());
            if (slaveTable == null) {
                errorMessage = "数据验证失败，数据源关联 [" + relation.getRelationName() + "] 的从表Id不存在！";
                return R.fail(errorMessage);
            }
            relation.setSlaveTable(slaveTable);
        }

		return R.data(relationList);
    }

    /**
     * 构建在线表的数据记录。
     *
     * @param table             在线数据表对象。
     * @param tableData         在线数据表数据。
     * @param forUpdate         是否为更新。
     * @param ignoreSetColumnId 忽略设置的字段Id。
     * @return 在线表的数据记录。
     */
    public R<List<ColumnData>> buildTableData(
            OnlineTable table, JSONObject tableData, boolean forUpdate, Long ignoreSetColumnId) {
        List<ColumnData> columnDataList = new LinkedList<>();
        String errorMessage;
        for (OnlineColumn column : table.getColumnMap().values()) {
            // 判断一下是否为需要自动填入的字段，如果是，这里就都暂时给空值了，后续操作会自动填补。
            // 这里还能避免一次基于tableData的查询，能快几纳秒也是好的。
            if (this.isAutoSettingField(column) || ObjectUtil.equal(column.getColumnId(), ignoreSetColumnId)) {
                columnDataList.add(new ColumnData(column, null));
                continue;
            }


            Object value = tableData.get(column.getColumnName());
			if(column.getPrimaryKey()){
				columnDataList.add(new ColumnData(column, value ));
				continue;
			}
			//判断是否有默认值字段
			if(StringUtils.isNotBlank(column.getColumnDefault())){
				columnDataList.add(new ColumnData(column,value == null?column.getColumnDefault():value));
				continue;
			}
			//slaveData是否存在该字段
			if(!tableData.containsKey(column.getColumnName())){
				continue;
			}
            // 对于主键数据的处理。
            if (column.getPrimaryKey()) {
                // 如果是更新则必须包含主键参数。
                if (forUpdate && value == null) {
                    errorMessage = "数据验证失败，数据表 ["
                            + table.getTableName() + "] 主键字段 [" + column.getColumnName() + "] 不能为空值！";
                    return R.fail(errorMessage);
                }
            } else {
                if (value == null && !column.getNullable()) {
                    errorMessage = "数据验证失败，数据表 ["
                            + table.getTableName() + "] 字段 [" + column.getColumnName() + "] 不能为空值！";
                    return R.fail(errorMessage);
                }
            }
            columnDataList.add(new ColumnData(column, value));
        }

        return R.data(columnDataList);
    }

    /**
     * 构建多个一对多从表的数据列表。
     *
     * @param datasourceId 数据源Id。
     * @param slaveData    多个一对多从表数据的JSON对象。
     * @return 构建后的多个一对多从表数据列表。
     */
    public R<Map<OnlineDatasourceRelation, List<List<ColumnData>>>> buildSlaveDataList(
            Long datasourceId, JSONObject slaveData,Boolean isForUpdate) {
        Map<OnlineDatasourceRelation, List<List<ColumnData>>> relationDataMap = new HashMap<>(slaveData.size());
        for (String key : slaveData.keySet()) {
            Long relationId = Long.parseLong(key);
            R<OnlineDatasourceRelation> relationResult = this.verifyAndGetRelation(datasourceId, relationId);
            if (!relationResult.isSuccess()) {
                return R.fail(relationResult.getMsg());
            }
            OnlineDatasourceRelation relation = relationResult.getData();
            List<List<ColumnData>> relationDataList = new LinkedList<>();
            relationDataMap.put(relation, relationDataList);
            OnlineTable slaveTable = relation.getSlaveTable();
            JSONArray slaveObjectArray = slaveData.getJSONArray(key);
            for (int i = 0; i < slaveObjectArray.size(); i++) {
                JSONObject slaveObject = slaveObjectArray.getJSONObject(i);
                R<List<ColumnData>> slaveColumnDataListResult =
                        this.buildTableData(slaveTable, slaveObject, isForUpdate, relation.getSlaveColumnId());
                if (!slaveColumnDataListResult.isSuccess()) {
                    return R.fail(slaveColumnDataListResult.getMsg());
                }
                relationDataList.add(slaveColumnDataListResult.getData());
            }
        }
        return R.data(relationDataMap);
    }

    /**
     * 将字符型字段值转换为与参数字段类型匹配的字段值。
     *
     * @param column 在线表单字段。
     * @param dataId 字符型字段值。
     * @return 转换后与参数字段类型匹配的字段值。
     */
    public Object convertToTypeValue(OnlineColumn column, String dataId) {
        if ("Long".equals(column.getObjectFieldType())) {
            return Long.valueOf(dataId);
        } else if ("Integer".equals(column.getObjectFieldType())) {
            return Integer.valueOf(dataId);
        }
        return dataId;
    }

    /**
     * 将字符型字段值集合转换为与参数字段类型匹配的字段值集合。
     *
     * @param column    在线表单字段。
     * @param dataIdSet 字符型字段值集合。
     * @return 转换后与参数字段类型匹配的字段值集合。
     */
    public Set<?> convertToTypeValue(OnlineColumn column, Set<String> dataIdSet) {
        if ("Long".equals(column.getObjectFieldType())) {
            return dataIdSet.stream().map(Long::valueOf).collect(Collectors.toSet());
        } else if ("Integer".equals(column.getObjectFieldType())) {
            return dataIdSet.stream().map(Integer::valueOf).collect(Collectors.toSet());
        }
        return dataIdSet;
    }

    /**
     * 下载数据。
     *
     * @param table     在线表对象。
     * @param dataId    在线表数据主键Id。
     * @param fieldName 数据表字段名。
     * @param filename  下载文件名。
     * @param asImage   是否为图片。
     * @param response  HTTP 应对对象。
     */
    public void doDownload(
		OnlineTable table, String dataId, String fieldName, String filename, Boolean asImage, HttpServletResponse response) {
        // 使用try来捕获异常，是为了保证一旦出现异常可以返回500的错误状态，便于调试。
        // 否则有可能给前端返回的是200的错误码。
        try {
            // 如果请求参数中没有包含主键Id，就判断该文件是否为当前session上传的。
            if (ObjectUtil.isEmpty(dataId)) {
//                if (!cacheHelper.existSessionUploadFile(filename)) {
//                    R.fail(HttpServletResponse.SC_FORBIDDEN, "");
//                    return;
//                }
            } else {
                Map<String, Object> dataMap =
                        onlineOperationService.getMasterData(table, null, null, dataId);
                if (dataMap == null) {
                    R.fail(HttpServletResponse.SC_NOT_FOUND, "");
                    return;
                }
                String fieldJsonData = (String) dataMap.get(fieldName);
                if (fieldJsonData == null) {
                    R.fail(HttpServletResponse.SC_BAD_REQUEST, "");
                    return;
                }
//                if (!BaseUpDownloader.containFile(fieldJsonData, filename)) {
//                    ResponseResult.output(HttpServletResponse.SC_FORBIDDEN);
//                    return;
//                }
            }
            OnlineColumn downloadColumn = null;
            for (OnlineColumn column : table.getColumnMap().values()) {
                if (column.getColumnName().equals(fieldName)) {
                    if (asImage) {
                        if (ObjectUtil.notEqual(column.getFieldKind(), FieldKind.UPLOAD_IMAGE)) {
                            R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
                            return;
                        }
                    } else {
                        if (ObjectUtil.notEqual(column.getFieldKind(), FieldKind.UPLOAD)) {
							R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
                            return;
                        }
                    }
                    downloadColumn = column;
                    break;
                }
            }
            if (downloadColumn == null) {
				R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
                return;
            }
//            BaseUpDownloader upDownloader = upDownloaderFactory.get(UploadStoreTypeEnum.LOCAL_SYSTEM);
//            upDownloader.doDownload(onlineProperties.getUploadFileBaseDir(),
//                    table.getModelName(), fieldName, filename, asImage, response);
            attachClient.download(response, null); // 需要获取dataMap中的对应附件ID进行下载
        } catch (Exception e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            log.error(e.getMessage(), e);
        }
    }

    /**
     * 上传数据。
     *
     * @param table      在线表对象。
     * @param fieldName  数据表字段名。
     * @param asImage    是否为图片。
     * @param uploadFile 上传的文件。
     */
    public void doUpload(OnlineTable table, String fieldName, Boolean asImage, MultipartFile uploadFile) throws Exception {
        OnlineColumn uploadColumn = null;
        for (OnlineColumn column : table.getColumnMap().values()) {
            if (column.getColumnName().equals(fieldName)) {
                if (asImage) {
                    if (ObjectUtil.notEqual(column.getFieldKind(), FieldKind.UPLOAD_IMAGE)) {
						R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
                        return;
                    }
                } else {
                    if (ObjectUtil.notEqual(column.getFieldKind(), FieldKind.UPLOAD)) {
						R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
                        return;
                    }
                }
                uploadColumn = column;
                break;
            }
        }
        if (uploadColumn == null) {
			R.fail(HttpServletResponse.SC_FORBIDDEN, ErrorCodeEnum.INVALID_UPLOAD_FIELD.getErrorMessage());
            return;
        }
		R<Attach>  attach = attachClient.upload(uploadFile);
		attach.getData().getId();
		// 将ID存到数据中并返回给前端
    }

    private boolean isAutoSettingField(OnlineColumn column) {
        return (ObjectUtil.equal(column.getFieldKind(), FieldKind.CREATE_TIME)
                || ObjectUtil.equal(column.getFieldKind(), FieldKind.CREATE_USER_ID)
                || ObjectUtil.equal(column.getFieldKind(), FieldKind.UPDATE_TIME)
                || ObjectUtil.equal(column.getFieldKind(), FieldKind.UPDATE_USER_ID)
                || ObjectUtil.equal(column.getFieldKind(), FieldKind.LOGIC_DELETE));
    }


	/**
	 * 设备小件提交流程验证远程测试是否结束
	 * @param datasourceId
	 * @param dataId
	 * @param slaveData
	 * @param task
	 * @param project_no
	 * @return
	 */
	public R<String> validateRemoteTest(Long datasourceId, String dataId, JSONObject slaveData, Task task,String project_no) {
		//查询新设备/小件明细表relation
		OnlineDatasourceRelation onlineDatasourceRelation = new OnlineDatasourceRelation();
		onlineDatasourceRelation.setRelationName("新设备明细");
		onlineDatasourceRelation.setDatasourceId(datasourceId);
		List<OnlineDatasourceRelation> onlineDatasourceRelationList = onlineDatasourceRelationService.getOnlineDatasourceRelationListWithRelation(onlineDatasourceRelation,null);
		OnlineDatasourceRelation desRelation = onlineDatasourceRelationList.get(0);
		String desRelationId = desRelation.getRelationId().toString();
		//从slavedata里面获取明细relation数据
		JSONArray slaveObjectArray = slaveData.getJSONArray(desRelationId);
		JSONObject desRelationObject = slaveObjectArray.getJSONObject(0);
		Integer test_type = desRelationObject.getInteger("test_type");
		Integer exp_test_type = desRelationObject.getInteger("exp_test_type");
		//立项直接提交
		if (StringUtils.isEmpty(dataId)){
			//立项发起远程测试
			if (test_type!=null&&test_type.intValue()==0){
				return R.fail("您选择了发起远程测试，只能先保存草稿，然后提交");
			}
		}else{ //先保存，再提交
			//查询远程测试relation
			OnlineDatasourceRelation onlineDatasourceRelation1 = new OnlineDatasourceRelation();
			onlineDatasourceRelation1.setRelationName("新设备/小件远程测试");
			onlineDatasourceRelation1.setDatasourceId(datasourceId);
			List<OnlineDatasourceRelation> onlineDatasourceRelationList1 = onlineDatasourceRelationService.getOnlineDatasourceRelationListWithRelation(onlineDatasourceRelation1,null);
			OnlineDatasourceRelation remoteRelation = onlineDatasourceRelationList1.get(0);
			//远程测试表
			OnlineTable remoteTable = onlineTableService.getById(remoteRelation.getSlaveTableId());
			//未发起流程，立项阶段，并选择了发起远程测试
			if (task == null && test_type!=null&&test_type.intValue()==0){
				List<OnlineFilterDto> filterList = new ArrayList<>();
				OnlineFilterDto onlineFilter1 = new OnlineFilterDto();
				onlineFilter1.setFilterType(FieldFilterType.EQUAL_FILTER);
				onlineFilter1.setTableName(remoteTable.getTableName());
				onlineFilter1.setColumnName("project_no");
				onlineFilter1.setColumnValue(project_no);
				OnlineFilterDto onlineFilter2 = new OnlineFilterDto();
				onlineFilter2.setFilterType(FieldFilterType.EQUAL_FILTER);
				onlineFilter2.setTableName(remoteTable.getTableName());
				onlineFilter2.setColumnName("newdevice_type");
				onlineFilter2.setColumnValue(1);
				filterList.add(onlineFilter1);filterList.add(onlineFilter2);
				long count1 = onlineOperationService.getPageTotal(remoteTable.getTableName(),null,null,filterList,null,null,null);
				if (count1==0){
					return R.fail("您还未提交远程测试，不能提交立项申请");
				}
				OnlineFilterDto onlineFilter3 = new OnlineFilterDto();
				onlineFilter3.setFilterType(FieldFilterType.NOT_EQUAL_FILTER);
				onlineFilter3.setTableName(remoteTable.getTableName());
				onlineFilter3.setColumnName("status");
				onlineFilter3.setColumnValue("确认测试结果_agree");
				filterList.add(onlineFilter3);
				long count2 = onlineOperationService.getPageTotal(remoteTable.getTableName(),null,null,filterList,null,null,null);
				if (count2>0){
					return R.fail("立项远程测试还未完成，不能提交立项申请");
				}
			}else if(task != null && exp_test_type!=null&&exp_test_type.intValue()==0){ //实验室测试发起远程测试
				List<OnlineFilterDto> filterList = new ArrayList<>();
				OnlineFilterDto onlineFilter1 = new OnlineFilterDto();
				onlineFilter1.setFilterType(FieldFilterType.EQUAL_FILTER);
				onlineFilter1.setTableName(remoteTable.getTableName());
				onlineFilter1.setColumnName("project_no");
				onlineFilter1.setColumnValue(project_no);
				OnlineFilterDto onlineFilter2 = new OnlineFilterDto();
				onlineFilter2.setFilterType(FieldFilterType.EQUAL_FILTER);
				onlineFilter2.setTableName(remoteTable.getTableName());
				onlineFilter2.setColumnName("newdevice_type");
				onlineFilter2.setColumnValue(2);
				filterList.add(onlineFilter1);filterList.add(onlineFilter2);
				long count1 = onlineOperationService.getPageTotal(remoteTable.getTableName(),null,null,filterList,null,null,null);
				if (count1==0){
					return R.fail("您还未提交远程测试，不能提交实验室测试");
				}
				OnlineFilterDto onlineFilter3 = new OnlineFilterDto();
				onlineFilter3.setFilterType(FieldFilterType.NOT_EQUAL_FILTER);
				onlineFilter3.setTableName(remoteTable.getTableName());
				onlineFilter3.setColumnName("status");
				onlineFilter3.setColumnValue("确认测试结果_agree");
				filterList.add(onlineFilter3);
				long count2 = onlineOperationService.getPageTotal(remoteTable.getTableName(),null,null,filterList,null,null,null);
				if (count2>0){
					return R.fail("实验室远程测试还未完成，不能提交实验室测试");
				}
			}
		}
		return R.success("验证成功");
	}


	/**
	 * 验证供应商不能被重复复制
	 * @param masterTable
	 * @param project_no
	 * @param copySupplierNo
	 * @return
	 */
	public R<String> validateSupplierCopy(OnlineTable masterTable,String project_no,String copySupplierNo) {
		String masterTableName = masterTable.getTableName();
		List<OnlineFilterDto> filterList1 = new ArrayList<>();
		OnlineFilterDto onlineFilter1 = new OnlineFilterDto();
		//项目编号
		onlineFilter1.setFilterType(FieldFilterType.EQUAL_FILTER);
		onlineFilter1.setTableName(masterTableName);
		onlineFilter1.setColumnName("project_no");
		onlineFilter1.setColumnValue(project_no);
		//复制供应商id
		OnlineFilterDto onlineFilter2 = new OnlineFilterDto();
		onlineFilter2.setFilterType(FieldFilterType.EQUAL_FILTER);
		onlineFilter2.setTableName(masterTableName);
		onlineFilter2.setColumnName("copy_supplier_no");
		onlineFilter2.setColumnValue(copySupplierNo);
		filterList1.add(onlineFilter1);filterList1.add(onlineFilter2);
		//根据项目编号和复制供应商id查询
		long count1 = onlineOperationService.getPageTotal(masterTableName,null,null,filterList1,null,null,null);
		//如果项目编号和供应商存在
		if (count1 > 0){
			//复制次数
			OnlineFilterDto onlineFilter3 = new OnlineFilterDto();
			onlineFilter3.setFilterType(FieldFilterType.EQUAL_FILTER);
			onlineFilter3.setTableName(masterTableName);
			onlineFilter3.setColumnName("copy_times");
			onlineFilter3.setColumnValue(3);
			//状态
			Set<Object> statusSet = new HashSet<>();
			statusSet.add("EN_Leader审批_refuse");
			statusSet.add("PCM审批_refuse");
			OnlineFilterDto onlineFilter4 = new OnlineFilterDto();
			onlineFilter4.setFilterType(FieldFilterType.IN_LIST_FILTER);
			onlineFilter4.setTableName(masterTableName);
			onlineFilter4.setColumnName("status");
			onlineFilter4.setColumnValueList(statusSet);
			filterList1.add(onlineFilter3);filterList1.add(onlineFilter4);
			//查询复制次数为3次，状态为驳回的次数
			long count2 = onlineOperationService.getPageTotal(masterTableName,null,null,filterList1,null,null,null);
			List<OnlineFilterDto> filterList2 = new ArrayList<>();
			//审核通过的状态
			OnlineFilterDto onlineFilter5 = new OnlineFilterDto();
			onlineFilter5.setFilterType(FieldFilterType.EQUAL_FILTER);
			onlineFilter5.setTableName(masterTableName);
			onlineFilter5.setColumnName("status");
			onlineFilter5.setColumnValue("PCM审批_agree");
			filterList2.add(onlineFilter1);filterList2.add(onlineFilter2);
			filterList2.add(onlineFilter5);
			//查询状态为审批通过的数据
			long count3 = onlineOperationService.getPageTotal(masterTableName,null,null,filterList2,null,null,null);
			if (count1 != (count2+count3)){
				return R.fail("该项目已经发起了此供应商复制，不能重复发起");
			}
		}
		return R.success("验证成功");
	}
}
